package com.estate.web.controller.report.home;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.estate.common.core.controller.BaseController;
import com.estate.common.core.domain.AjaxResult;
import com.estate.common.utils.StringUtils;
import com.estate.system.domain.vo.ClientResult;
import com.estate.system.service.impl.DataEnquiriesServiceImpl;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home/leaseAgent")
public class HomeLeaseAgentController extends BaseController {

    @Resource
    private DataEnquiriesServiceImpl dataEnquiriesServiceImpl;


    @GetMapping("/getClientRequests")
    public AjaxResult getClientRequestsDetail(Map<String, Object> paramData) {
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> newEnquireMap = dataEnquiriesServiceImpl.getSevenDayNewEnquire(paramData);
        if(!CollectionUtils.isEmpty(newEnquireMap)){
            Long sevenDaysAgoCount = (Long) newEnquireMap.get("sevenDaysAgoCount");
            Long fourteenDaysAgoCount = (Long) newEnquireMap.get("fourteenDaysAgoCount");
            Double upOrDown = (Double) newEnquireMap.get("addPercentage");
            result.put("clientRequest", sevenDaysAgoCount - fourteenDaysAgoCount);
            result.put("upOrDown", upOrDown);
        }
        return AjaxResult.success("success", result);
    }

    @GetMapping("/getNewListings")
    public AjaxResult getNewListings(Map<String, Object> paramData) {
        Map<String, Object> sevenDayNewListing = dataEnquiriesServiceImpl.getSevenDayNewListing(paramData);
        Map<String, Object> result = new HashMap<>();
        if (StringUtils.isNotEmpty(sevenDayNewListing)) {
            Long sevenDaysAgoCount = (Long) sevenDayNewListing.get("sevenDaysAgoCount");
            Long fourteenDaysAgoCount = (Long) sevenDayNewListing.get("fourteenDaysAgoCount");
            Double upOrDown = (Double) sevenDayNewListing.get("addPercentage");
            result.put("newListings", sevenDaysAgoCount - fourteenDaysAgoCount);
            result.put("upOrDown", upOrDown);
            return AjaxResult.success("success", result);
        } else {
            return AjaxResult.error("fail", null);
        }
    }

    @GetMapping("/getUpcomingTasks")
    public AjaxResult getUpcomingTasks(Map<String, Object> paramData) {

        Map<String, Object> upcomingTasks = dataEnquiriesServiceImpl.getUpcomingTasks(paramData);
        return AjaxResult.success("success", upcomingTasks);
    }
    @GetMapping("/getDetailTask")
    public AjaxResult getDetailTask(Map<String, Object> param) {
        return AjaxResult.success("success", dataEnquiriesServiceImpl.getDetailTask(param));
    }

    @GetMapping("/getRankingOfTransactionsNumber")
    public AjaxResult getRankingOfTransactionsNumber(Map<String, Object> paramData) {
        List<Map<String, Object>> trendsInRentalAmounts = dataEnquiriesServiceImpl.getRankingOfTransactionsNumber(paramData);
        return AjaxResult.success("success", trendsInRentalAmounts);
    }


    @GetMapping("/getTrendsInRentalAmounts")
    public AjaxResult getTrendsInRentalAmounts(Map<String, Object> paramData) {

        List<Map<String, Object>> trendsInRentalAmounts = dataEnquiriesServiceImpl.getTrendsInRentalAmounts(paramData);
        return AjaxResult.success("success", trendsInRentalAmounts);
    }

    @GetMapping("/getTrendOfTransactions")
    public AjaxResult getTrendOfTransactions(Map<String, Object> paramData) {
        List<Map<String, Object>> trendOfTransaction = dataEnquiriesServiceImpl.getTrendOfTransactions(paramData);
        return AjaxResult.success("success", trendOfTransaction);
    }

    @GetMapping("/getMessageSent")
    public AjaxResult getMessageSent(ClientResult bo) {
        startPage();
        Page<ClientResult> dataViewPageList = dataEnquiriesServiceImpl.getMessageSent(bo);
        return AjaxResult.success("查询成功", getDataTable(dataViewPageList));
//        Page<ClientResult> clientList = dataEnquiriesServiceImpl.getMessageSent(paramData);
//        return AjaxResult.success("success", clientList);

    }

}
